//
package com.crm.config.swagger;

import cn.hutool.core.collection.CollectionUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;


@Configuration
//@Import(BeanValidatorPluginsConfiguration.class)、
@EnableSwagger2WebMvc
public class SwaggerConfiguration {

    @Bean(value = "defaultApi")
    public Docket defaultApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("crm")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.crm.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(CollectionUtil.newArrayList(apiKey()));

    }
    private ApiKey apiKey() {
        return new ApiKey("Bearer Authorization", "Authorization", "header");
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("crm")
                .description("客户关系系统")
                .termsOfServiceUrl("https://doc.xiaominfo.com/")
                .contact(new Contact("junxian.dou", "", "602137101@qq.com"))
                .version("1.0")
                .build();
    }
}
